#include "teacherlogin.h"
#include "ui_teacherlogin.h"
#include <iostream>
#include <QMessageBox>

using namespace std;

TeacherLogin::TeacherLogin(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::TeacherLogin)
{
    ui->setupUi(this);
    this->setWindowIcon(QIcon(":/img/login.jpg"));
    this->tls = new TeacherLoginSuccess;
    connect(tls,SIGNAL(back2login()),this,SLOT(reshow()));
}

TeacherLogin::~TeacherLogin()
{
    delete ui;
}

void TeacherLogin::reshow()
{
    this->show();
}

void TeacherLogin::on_backmain_clicked()
{
    emit back2main();
    cout << "student login send signal" << endl;
    this->close();
}
void TeacherLogin::on_submit_clicked()
{
    string username = ui->usernameLineEdit->text().toStdString();
    string password = ui->passwordLineEdit->text().toStdString();
    bool authSuccess = username == "lxy1" && password == "12345";
    if (authSuccess)
    {
        this->hide();
        tls->show();
    }
    else
    {
        QMessageBox::critical(this,
               tr("登录失败"),
               tr("用户名或密码不正确"),
               QMessageBox::Ok | QMessageBox::Cancel,
               QMessageBox::Ok);
    }
}
